//遍历ajaxUrl 请求接口
$(function(){
    ajaxUrlPost();
});

function  ajaxUrlPost() {
    $(".ajaxUrl").each(function(){
        var $this = $(this);
        ajaxUrl($this.attr("ajax-url"), $this);
    });
    //点击请求接口
    $(".ajaxUrl-click").click(function(){
        var $this = $(this);
        var $ajaxResult = $(this).find(".ajax-result");
        ajaxUrl($this.attr("ajax-url"), $ajaxResult)
    });
}

/**
 * ajaxUrl
 * @param url 请求地址
 * @param ele 需要改变值的元素
 */
function ajaxUrl(url, ele) {
    var obj = $('.timeSpace').serialize2object();
    $.ajax({
        type:"post",
        data:obj,
        url:url,
        success: function (data) {
            if(data.code==0){
                if(null!=data.data){
                    var countnum = 0;
                    if (data.data > 10000) {
                        countnum = parseInt((data.data) / 10000);
                        countnum += '<font style="font-size: 12px"> 万</font>';
                    } else {
                        countnum = data.data;
                    }
                    ele.html(countnum);
                }else{
                    ele.html("0");
                }
            }else{
                ele.html("--");
            }
        },
        error:function(){
            ele.html("--");
        }
    })
}

//部门业绩排名
function ranking(type) {
    $.ajax({
        type:"get",
        url:sysInfo.basePath+"/orf/work/workPerformanceTeamTop5.do?type="+type,
        success: function (data) {
            if(data.result==0){
                var dataobject = data.dataobject;
                if(dataobject!=null&&dataobject.length>0) {
                    $('#team_ranking table').show();
                    var resHtm='';
                    $.each(dataobject,function (i,res) {
                        var x = i + 1;
                        resHtm+='<tr>' +
                            '<td>'+x+'</td>' +
                            '<td>'+res.orgName+'</td>' +
                            '<td>'+res.totalAmount +'</td>' +
                            '</tr>';
                    });
                    $('#team_ranking table tbody').empty().append(resHtm);
                }else{
                    //没有数据
                    $("#team_ranking").find('.table-wait-content').text("没有数据");

                }
            }else{
                $("#team_ranking").find('.table-wait-content').text("获取数据异常");
            }
        }
    });
}


